<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
	<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
	<title></title>
	<script type="text/javascript" src="../../js/boot.js"></script>
</head>

<body>
	<div class="mini-splitter" style="width: 100%; height: 100%;">
		<div size="240" showCollapseButton="true">
			<div class="mini-fit">
				<ul id="pageTree" class="mini-tree" style="width: 100%;" showTreeIcon="true" allowDrag="true" allowDrop="true" textField="label"
					idField="menuID" resultAsTree="false">
				</ul>
			</div>
		</div>

		<div showCollapseButton="true">
			<div class="mini-toolbar" style="padding: 2px; border-top: 0; border-left: 0; border-right: 0;">
				<a class="mini-button" iconCls="icon-add" plain="true" onclick="addMenu()">新增</a>
				<a class="mini-button" iconCls="icon-remove" plain="true" onclick="removeMenu()">删除</a>
				<a class="mini-button" iconCls="icon-save" plain="true" onclick="saveMenu()">保存</a>
				<a class="mini-button" iconCls="icon-save" plain="true" onclick="publish()">发布</a>
			</div>

			<div id="dataForm">
				<input name="parentID" class="mini-hidden" />
				<input name="menuID" class="mini-hidden" />
				<input name="weixinID" class="mini-hidden" />
				<fieldset style="width: 98%;">
					<legend>
						<span>菜单信息</span>
					</legend>
					<div class="fieldset-body">
						<table class="nteport-base-table2" style="width: 100%;">
							<tr>
								<td style="width: 10%; text-align: right;">菜单标题：</td>
								<td style="width: 25%"><input name="label" class="mini-textbox" style="width: 90%" /></td>
								<td style="width: 10%; text-align: right;">动作类型：</td>
								<td style="width: 25%"><input name="menuType" class="mini-combobox" textField="text" valueField="id" data="menuTypes"
										style="width:90%" /></td>
							</tr>
							<tr>
								<td style="text-align: right;">菜单KEY值：</td>
								<td><input name="menuKey" class="mini-textbox" style="width: 90%" /></td>
								<td style="text-align: right;">网页链接：</td>
								<td><input name="menuUrl" class="mini-textbox" style="width: 90%" /></td>
							</tr>
							<tr>
								<td style="text-align: right;">排序：</td>
								<td><input name="sequence" class="mini-spinner" style="width: 90%" /></td>
								<td style="text-align: right;">素材编号：</td>
								<td><input name="mediaId" class="mini-textbox" style="width: 90%" /></td>
							</tr>
							<tr>
								<td style="text-align: right;">APPID：</td>
								<td><input name="appId" class="mini-textbox" style="width:90%" /></td>
								<td style="text-align: right;">页面路径：</td>
								<td><input name="pagePath" class="mini-textbox" style="width:90%" /></td>
							</tr>
						</table>
					</div>
				</fieldset>
			</div>

		</div>
	</div>
</body>

<script type="text/javascript">
	var menuTypes = [{
		"id": "click",
		"text": "点击事件"
	}, {
		"id": "view",
		"text": "页面跳转"
	}];
	miniInit();

	var tree = mini.get("pageTree");
	var pageForm = new mini.Form("#dataForm");

	// 加载浅蓝色背景和去除滚动条
	$('.mini-splitter').addClass('bg');
	//$('.fieldset-body-body').addClass('bg');

	tree.url = http.getUrl("/weixin/menu/list.do");
	tree.load(tree.url);

	var editNode = null; // 当前编辑的节点
	/*********************************************************
	 * 左侧目录树的鼠标点击事件
	 *********************************************************/
	tree.on("nodedblclick", function (e) {
		// debugger
		editNode = e.node;
		tree.loadNode(editNode);
		if (editNode) {
			pageForm.setData(editNode);
		}
	});

	/*********************************************************
	 * 操作方法
	 *********************************************************/
	/**
	 * 新增
	 */
	function addMenu() {
		var node = tree.getSelectedNode();
		if (node) {
			var newRow = {
				"parentID": node.menuID,
				"weixinID": node.weixinID
			};
			pageForm.setData(newRow);
			// debugger
		} else {
			miniui.showWarnMessageBox("请先选择菜单创建的位置！");
		}
	}

	/**
	 * 保存
	 */
	function saveMenu() {
		var data = pageForm.getData();
		debugger
		http.post("/weixin/menu/save.do", data, function (page) {
			// 如果是修改保存，刷新父节点
			if (data.dicID) {
				var parent = tree.getParentNode(editNode);
				tree.loadNode(parent);
			}
			// 如果是新增，刷新本节点的所有子节点
			else {
				tree.loadNode(editNode);
			}
		});
	}

	/**
	 * 删除
	 */
	function removeMenu() {
		var node = editNode;
		if (node) {
			mini.confirm("确定要删除" + editNode.label + "吗？", "确定？", function (action) {
				if (action == "ok") {
					params = {
						"menuID": node.menuID
					}
					http.post("/weixin/menu/delete.do", params, function (page) {
						tree.removeNode(node);
						pageForm.setData([]);
					});
				}
			});
		} else {
			showWarn("请先选择要删除的菜单！");
		}
	}

	function publish() {
		var node = tree.getSelectedNode();
		if (node == null || node == undefined) {
			mini.alert("请先选择要发布的微信菜单", "错误", null);
			return;
		}
		var data = { "weixinID": node.weixinID };
		debugger
		http.post("/weixin/menu/publish.do", data, function (page) {
			mini.alert("发布成功", "提示", null);
		});
	}
</script>

</html>